import { createStore } from 'vuex'
import { getItem, setItem } from '@/utils/storage.js'

const TOKEN_KEY = 'TOUTIAO_USER'
export default createStore({
  state: {
    user: getItem(TOKEN_KEY)
  },
  mutations: {
    // 用户登录时调用此方法在vuex中存储
    saveToken (state, res) {
      // 将token储存到本地
      if (res === null) {
        state.user = null
      } else {
        state.user = res.data.data
      }
      setItem(TOKEN_KEY, state.user)
    }
  },
  actions: {
  },
  modules: {
  }
})
